package com.demo.service;

import com.demo.model.User;
import org.springframework.stereotype.Service;
import java.util.*;

@Service
public class UserService {
    private final Map<Long, User> userRepo = new HashMap<>();
    private long idCounter = 1;

    public User getUserById(Long id) {
        return userRepo.get(id);
    }
    public String createUser(User user) {
        user.setId(idCounter++);
        userRepo.put(user.getId(), user);
        return "success";
    }
    public List<User> getAllUsers() {
        return new ArrayList<>(userRepo.values());
    }
    public void updateUser(User user) {
        userRepo.put(user.getId(), user);
    }
    public void deleteUser(Long id) {
        userRepo.remove(id);
    }
} 